﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Web.Http;

namespace F2S.oAuth
{
    public enum OauthExecutionStatusCodes
    {
        OK,
        Unauthorized,
        Forbidden,
        Other
    }

    public class OAuthExecutionResult
    {
        public System.Net.Http.HttpResponseMessage HttpResponse { get; protected set; }
        public string Data { get; protected set; }

        public OauthExecutionStatusCodes StatusCode { get; protected set; }

        public bool Success
        {
            get
            {
                if (HttpResponse == null) return false;
                return HttpResponse.IsSuccessStatusCode;
            }
        }

        public OAuthExecutionResult()
        {
        }

        public OAuthExecutionResult(System.Net.Http.HttpResponseMessage response, string data = null)
        {
            HttpResponse = response;
            Data = data;
        }
    }

    public class OAuthExecutionResult<T> : OAuthExecutionResult
    {
        public T Object { get; private set; }

        public OAuthExecutionResult(System.Net.Http.HttpResponseMessage httpResponse, OauthExecutionStatusCodes statusCode)
        {
            HttpResponse = httpResponse;
            StatusCode = statusCode;
        }

        public OAuthExecutionResult(System.Net.Http.HttpResponseMessage httpResponse, OauthExecutionStatusCodes statusCode, string data, T o)
        {
            HttpResponse = httpResponse;
            StatusCode = statusCode;
            Data = data;
            Object = o;
        }

        public OAuthExecutionResult(System.Net.Http.HttpResponseMessage httpResponse, string data, T o) : base(httpResponse, data)
        {
            HttpResponse = httpResponse;
            Data = data;
            Object = o;
        }

        public override string ToString()
        {
            return string.Format("{0} {1}", StatusCode, Object);
        }
    }
}
